//
//  WBNavigationController.swift
//  ZWWEIBO
//
//  Created by xzw on 2017/11/21.
//  Copyright © 2017年 xzw. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //push的时候隐藏底部tabar
        if childViewControllers.count > 0 {
           viewController.hidesBottomBarWhenPushed = true
            
            //添加返回按钮
            if let vc = viewController as? WBBaseViewController{
                
                var title = "返回"
                if childViewControllers.count == 1{
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popParent),isBackButton : true)
                
            }
            
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func popParent(){
        
        popViewController(animated: true)
    }

}
